#ifndef GLDISPLAY_H
#define GLDISPLAY_H

#include <QGLWidget>
#include <QMouseEvent>
#include <QMoveEvent>
#include <QPoint>
#include <QMatrix4x4>

#define NULLPOINT   QPoint(-1,-1)
#define EPSILON     0.001

class GLDisplay : public QGLWidget
{
    Q_OBJECT

    QPoint rigthPressedPoint;
    QPoint leftPressedPoint;
    float zoom;

    QMatrix4x4 m_rotations;
    QQuaternion m_interactiveQuartenion;

    QVector3D eye;
    QVector3D up;
    QVector3D lookAt;
    bool salvarEye;

    double degreeFromCos(double)const;

signals:
    void drawModel(void);
    void lightSetup(void);
    void mouseRigthMove(QPoint ini, QPoint curr);
    void mouseRigthFinish(QPoint ini, QPoint curr);
    void mouseLeftMove(QPoint ini, QPoint curr);
    void mouseLefthFinish(QPoint ini, QPoint curr);
    void mouseCancel();
    void deletePressed();

public:
    GLDisplay(QWidget *parent = 0);
    ~GLDisplay();

    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();

    void salvarEyeRotation();

    static float xpos;
    static float ypos;
    static float zpos;
    static float xrot;
    static float yrot;
    static float angle;
    static void keyboard (int key);

    void setInteractiveQuartenion(const QQuaternion& quaternion);
    const QQuaternion& interactiveQuartenion(void)const;

    QVector3D getEye();
    QVector3D getLookAt();
    QVector3D getUp();

private:
    void mousePressEvent ( QMouseEvent * event );
    void mouseReleaseEvent ( QMouseEvent * event );
    void mouseMoveEvent(QMouseEvent *);
    float xDist(float aspect);
    float yDist(float aspect);

};


#endif // GLDISPLAY_H
